// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/accesscontrol/api/AccessControlPointDeviceApi'

import ComClass from '@api/ComQuery'

import ListClass from '@api/accesscontrol/model/AccessControlPointDeviceDto'
import DelClass from '@api/accesscontrol/model/AccessControlPointDeviceDeleteReq'
import SyncClass from '@api/accesscontrol/model/AccessControlPointDeviceSyncReq'

const AddClass = ListClass
const EditClass = ListClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询门禁点设备') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'accessControlPointDeviceQuery', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增门禁点设备') {
    const DTO = CORE.grpcDTO(AddClass, one)
    await CORE.grpc(TIP, CLIENT, 'accessControlPointDeviceSave', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async edit(one, TIP = '修改门禁点设备') {
    const DTO = CORE.grpcDTO(EditClass, one)
    await CORE.grpc(TIP, CLIENT, 'accessControlPointDeviceUpdate', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除门禁点设备') {
    const DTO = CORE.grpcDTO(DelClass, { ids: id })
    await CORE.grpc(TIP, CLIENT, 'accessControlPointDeviceDelete', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 同步 —————————————————————————————— //

  async sync({ id }, TIP = '门禁点设备同步') {
    const DTO = CORE.grpcDTO(SyncClass, { id })
    await CORE.grpc(TIP, CLIENT, 'accessControlPointDeviceSync', DTO)
    return CORE.grpcOK(TIP)
  },
}
